var app = getApp();

Page({
    data: {
        listName:"",
        listId:"",
        listArr:[],
        serveList:[],
        pageCurrent:1,
        pageSize:6,
        pageNum:"",  //总页数
        imgUrl:app.globalData.imgUrl,
        loading:false,   //"上拉加载中"
        loadingComplete:false,   //"加载完成"
        topid:""
    },
    onLoad: function (e) {
        var that = this;
        var currentId=e.id;
        var currentName=e.name;
        var topid = e.topid;
        that.setData({
            listId: currentId,
            listName: currentName,
            navH: app.globalData.navHeight,
            marH: app.globalData.navHeight+20,
            topid: topid
        });
        that.getlist();
    },
    getlist:function(){
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/index/goodsList",
            data: {
                page: that.data.pageCurrent,
                pagesize: that.data.pageSize,
                category_id: that.data.listId
            },
            header: {  
                'content-type': 'application/x-www-form-urlencoded' 
            },
            method: "POST",
            dataType: "json",
            success: function (res) {
                console.log(res);
                if (res.statusCode === 200) {
                    var listPageNum = res.data.data.last_page;
                    for (var i = 0; i < res.data.data.data.length; i++) { 
                        that.data.serveList.push(res.data.data.data[i]);
                    }
                    var listData = that.data.serveList;
                    that.setData({
                        listArr: listData,
                        pageNum:listPageNum
                    })
                }
            },
            
        });
    },
    navBack: function () {
      wx.navigateBack({
        delta: 1
      })
    },
    onReachBottom: function () {
        let that = this;
        if (that.data.pageCurrent < that.data.pageNum) {
            that.setData({
                loading:true,
                loadingComplete:false,
                pageCurrent: that.data.pageCurrent + 1
            })
            that.getlist();
        }else if(that.data.pageCurrent >= that.data.pageNum){
            that.setData({
                loading:false,
                loadingComplete:true
            })
        }
    }
})
